﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using RG.Common.Export;
using Microsoft.Practices.Unity;
using RG.Common.WPF;

namespace RG.Common.WPF.BaseSelector
{
    [SupportDataBinding]
    public class BaseSelectorFrameVM : ILoadFrame
    {
        [Dependency]
        public WorkplaceWorker Worker { get; set; }


        public ObservableCollection<INamed> Items { get; set; }
        public ObservableCollection<IColumnInfo> Columns { get; set; }

        public void Load(Func<List<INamed>> func)
        {
            Worker.Do(func, x =>
            {
                Items = x.ToObservableCollection();
            });
        }

        public INamed SelectedItem { get; set; }

        [InjectionConstructor]
        public BaseSelectorFrameVM(IUnityContainer cfg)
        {
            Items = new ObservableCollection<INamed>();
            Columns = new ObservableCollection<IColumnInfo>()
                          {
                              new ColumnInfoString<INamed>("Название",400,x=>x.Name),
                          };
        }
        
        public void BeginEdit()
        {
        }

        public void EndEdit()
        {
        }

        public void CancelEdit()
        {
        }

        public string LastError()
        {
            if (SelectedItem == null) return "ошибочка";
            return string.Empty;
        }
    }
}
